package com.lk.demo.b.service;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(name = "lk-a" , fallback = AServiceFeignClient.AServiceFeignClientHystrix.class)
public interface AServiceFeignClient {

    @GetMapping(value = "/v1/api/books")
    String getBooks(@RequestHeader("Authorization") String authorizationToken);

    @GetMapping(value = "/hello")
    String hello(@RequestParam("name") String name);

  /*  @PostMapping(value = "/api-gateway/v1/api/books")
    HttpServletResponse saveBook(@RequestHeader("Authorization") String authorizationToken, @RequestBody Book book);

    @GetMapping(value = "/api-gateway/v1/api/books")
    HttpServletResponse getBooks(@RequestHeader("Authorization") String authorizationToken);

    @GetMapping(value = "/api-gateway/v1/api/books/{bookId}")
    HttpServletResponse getBook(@RequestHeader("Authorization") String authorizationToken, @PathVariable("bookId") Integer bookId);

    @PutMapping(value = "/api-gateway/v1/api/books/{bookId}")
    HttpServletResponse updateBook(@RequestHeader("Authorization") String authorizationToken, @PathVariable("bookId") Integer bookId, @RequestBody Book book);

    @DeleteMapping(value = "/api-gateway/v1/api/books/{bookId}")
    HttpServletResponse deleteBook(@RequestHeader("Authorization") String authorizationToken, @PathVariable("bookId") Integer bookId);

    @Component
    public class AServiceFeignClientHystrix implements AServiceFeignClient {


        @Override
        public BaseResponse saveUser(User user) {
            System.out.println("打开了断路器--->" + user);
            return ApiResult.error(ApiCode.SERVER_IS_BUSY);
        }

        @Override
        public ApiResult getUser(@PathVariable(value = "uid") String uid) {
            System.out.println("打开了断路器--->" + uid);
            return ApiResult.error(ApiCode.SERVER_IS_BUSY);
        }

    }
*/
  @Component
  class AServiceFeignClientHystrix implements AServiceFeignClient {

      @Override
      @GetMapping(value = "/v1/api/books")
      public  String getBooks(@RequestHeader("Authorization") String authorizationToken){
          System.out.println("打开了断路器--->" + authorizationToken);
          return "{}";
      };
      @Override
      @GetMapping(value = "/hello")
      public  String hello(String name){
          System.out.println("打开了断路器--->" + name);
          return "{}";
      }

  }
}